
import * as UmfDialog from '../../../utils/UmfDialog.js';
const regexUtils = require('../../../utils/RegexUtils.js');
import idCradType from '../../../common/code/pickerList/idCradType.js';
const constants = require('../../../common/Constants.js');
const enterprisePage = {

  //是否开通POS
  switchChange_qy: function (e) {
    //如果 不开通企业pos  用户选择对私  报错
    if (!e.detail.value && this.data.settlementType == "0") {
      UmfDialog.show("如需对私结算请修改商户类型为小微");
      this.setData({
        isEnterprisePos:true
      });
      return;
    } else {
      if (this.data.cacheManager_qy) {
        this.data.cacheManager_qy.cacheFunc({ [e.target.id]: e.detail.value });
      }
      this.setData({
        isEnterprisePos: e.detail.value
      });
    }
  },


  alertClick: function (e) {
    let itemKey = e.currentTarget.id;
    let msg = "";
    // if (itemKey == "correlateBankNum") {
    msg = "请通过企业网银或通过网页查询。访问地址已自动复制请打开浏览器粘贴即可";
    // }
    UmfDialog.show(msg, () => {
      wx.setClipboardData({
        data: 'https://www.hebbank.com/corporbank/otherBankQueryWeb.do',
        success: function (res) {
          wx.getClipboardData({
            success: function (res) {
              console.log("复制成功");
            }
          })
        }
      })

    }, true);

  },

  //普通radio点击事件
  radioSelectedChange: function (e) {
    console.log(this.data.cacheStorageData);
    switch (e.target.id) {
      case "licenseType":
        this.setData({
          licenseType: e.detail.value
        })
        break;
      case "settlementType":
        if (e.detail.value == "0" && !this.data.isEnterprisePos) {
          UmfDialog.show("如需对私结算请修改商户类型为小微");
          this.setData({
            settlementType: "1",
          })
          return;
        }
        this.setData({
          settlementType: e.detail.value,
        })
        break;
    }
    if (this.data.cacheManager_qy) {
      this.data.cacheManager_qy.cacheFunc({ [e.target.id]: e.detail.value });
    }
  },

  inputEvent: function (e) {
    if (this.data.cacheManager_qy) {
      this.data.cacheManager_qy.cacheFunc({ [e.currentTarget.id]: e.detail.value });
    }
  },


  onNConfirmCB: function (idx, ret, code) {
    if (idx == "1") {
      this.setData({
        bankName:ret
      });
      
      if (this.data.cacheManager_qy) {
        this.data.cacheManager_qy.cacheFunc({ "bankName": ret });
      }
    }

    if (idx == "0") {
      this.setData({
        ciertiType:ret
      });
      if (this.data.cacheManager_qy) {
        this.data.cacheManager_qy.cacheFunc({ "ciertiType": ret });
      }
    }

  },

  //更多银行
  moreBankClick: function () {
    wx.navigateTo({
      url: '/pages/basisInfo/storeInfo/moreBankPage/moreBankPage'
    });
  },


  /*
     营业执照、组织机构、证件有效期radio
     长期  e.detail.value==0
     截止日期  e.detail.value==1
  */
  blRadioValidChange: function (e) {
    switch (e.target.id) {
      case "busLice_validity":
        this.setData({
          isBusLiceDead: e.detail.value == "1" ? true : false
        })
        break;
      case "organization_validity":
        this.setData({
          isOrganiDead: e.detail.value == "1" ? true : false
        })
        break;
      case "IDCard_validity":
        this.setData({
          isIDCardDead: e.detail.value == "1" ? true : false
        })
        break;

    }
    if (this.data.cacheManager_qy) {
      this.data.cacheManager_qy.cacheFunc({ [e.target.id]: e.detail.value });
    }
  },

  /*
     营业执照、组织机构、证件有效期
     滚动监听
  */

  onCardValidChange: function (e) {
    switch (e.target.id) {
      case "licenseValidDate":
        this.setData({
          licenseValidDate: e.detail.value
        });
        break;
      case "regisValidDate":
        this.setData({
          regisValidDate: e.detail.value
          });
        break;
      case "vldEndDt":
        this.setData({
          vldEndDt: e.detail.value
          });
        break;
      case "busRegisterDate":
        this.setData({
          busRegisterDate: e.detail.value
        });

    }
    if (this.data.cacheManager_qy) {
      this.data.cacheManager_qy.cacheFunc({ [e.target.id]: e.detail.value });
    }
  },

  _check_enterpriseData: function (formValues) {
    //(1)营业执照类型为普通
    if (formValues.licenseType == "0") {

      var errorMsg="";
      let storeValues = [
        [formValues.enLicenseNo, constants.RegexTypes.BUSILICENSENO],//营业执照
        [formValues.enterpriseName, constants.RegexTypes.MERCHANTFULLNAME],//企业全称
        [formValues.registrationNo, constants.RegexTypes.REGISTRATIONNO],//组织机构号
        [formValues.enterpriseKind, constants.RegexTypes.MAINBUSINESS],//主营业务
        //  [formValues.enterRegistAddr, constants.RegexTypes.REGISTEREDADDR],//注册地址
        [formValues.regAmt, constants.RegexTypes.REGAMT],//注册资金
      ];
      errorMsg = regexUtils.regexTypesWithMsg(storeValues);
      if (errorMsg) {
        return errorMsg;
      }
      //TODO注册日期   税务登记号
      if (!formValues.licenseValidDate) {
        return "请选择营业执照有效期";
      }
      if (!formValues.regisValidDate) {
        return "请选择组织机构号有效期";
      }

    } else if (formValues.licenseType == "1") {
      //判断社会信用代码
    }
    //法人信息判断
    let storeValues = [
      [formValues.lawyer, constants.RegexTypes.PROPRIETORNAME],//法人
      [formValues.certCode, constants.RegexTypes.ID_CARD],//法人身份证
    ];
    errorMsg = regexUtils.regexTypesWithMsg(storeValues);
    if (errorMsg) {
      return errorMsg;
    }
    if (!formValues.vldEndDt) {
      return "请选择证件有效期";
    }
    //如果对公结算
    if (formValues.settlementType == "1") {
      if (!this.data.cacheStorageData_qy.bankName) {
        return "请选择银行名称";
      }
      errorMsg = regexUtils.regexTypeWithMsg(formValues["bkAcId"], constants.RegexTypes.BKACID);
      if (errorMsg) {
        return errorMsg;
      }
      if (formValues["joinBankNo"].length < 6) {
        return "请输入正确的联行号";
      }
    }
  },


};
export default enterprisePage;